{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.6-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python38664bite0826404ec9f4f88a00ca1565c140931",
   "display_name": "Python 3.8.6 64-bit"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "&#39;\\n列表的方法\\n&#39;"
     },
     "metadata": {},
     "execution_count": 1
    }
   ],
   "source": [
    "'''\n",
    "列表的方法：无非就是增、删、改、查\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "[&#39;apple&#39;, &#39;orange&#39;, &#39;pear&#39;, &#39;banana&#39;, &#39;kiwi&#39;, &#39;apple&#39;, &#39;banana&#39;, &#39;tomato&#39;]"
     },
     "metadata": {},
     "execution_count": 1
    }
   ],
   "source": [
    "fruits = ['apple','orange','pear','banana','kiwi','apple','banana']\n",
    "another_fruits = ['graph','coconut']\n",
    "signal_fruit = 'tomato'\n",
    "# 增加\n",
    "fruits.append(signal_fruit)\n",
    "fruits"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "[&#39;apple&#39;,\n &#39;orange&#39;,\n &#39;pear&#39;,\n &#39;banana&#39;,\n &#39;kiwi&#39;,\n &#39;apple&#39;,\n &#39;banana&#39;,\n &#39;tomato&#39;,\n &#39;graph&#39;,\n &#39;coconut&#39;]"
     },
     "metadata": {},
     "execution_count": 2
    }
   ],
   "source": [
    "fruits.extend(another_fruits)\n",
    "fruits\n",
    "# fruits.append(another_fruits) 会是什么结果呢？\n",
    "#['apple','orange','pear','banana','kiwi','apple','banana','tomato','graph','coconut',['graph', 'coconut']]\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "[&#39;tomato&#39;,\n &#39;apple&#39;,\n &#39;orange&#39;,\n &#39;pear&#39;,\n &#39;banana&#39;,\n &#39;kiwi&#39;,\n &#39;apple&#39;,\n &#39;banana&#39;,\n &#39;tomato&#39;,\n &#39;graph&#39;,\n &#39;coconut&#39;]"
     },
     "metadata": {},
     "execution_count": 3
    }
   ],
   "source": [
    "fruits.insert(0,signal_fruit)\n",
    "fruits"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "[&#39;apple&#39;,\n &#39;orange&#39;,\n &#39;pear&#39;,\n &#39;banana&#39;,\n &#39;kiwi&#39;,\n &#39;apple&#39;,\n &#39;banana&#39;,\n &#39;tomato&#39;,\n &#39;graph&#39;,\n &#39;coconut&#39;,\n &#39;graph&#39;,\n &#39;coconut&#39;]"
     },
     "metadata": {},
     "execution_count": 12
    }
   ],
   "source": [
    "fruits.remove('tomato')\n",
    "fruits"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "[&#39;tomato&#39;,\n &#39;apple&#39;,\n &#39;orange&#39;,\n &#39;pear&#39;,\n &#39;banana&#39;,\n &#39;kiwi&#39;,\n &#39;apple&#39;,\n &#39;banana&#39;,\n &#39;tomato&#39;,\n &#39;graph&#39;]"
     },
     "metadata": {},
     "execution_count": 4
    }
   ],
   "source": [
    "abandon = fruits.pop()\n",
    "fruits"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "&#39;coconut&#39;"
     },
     "metadata": {},
     "execution_count": 5
    }
   ],
   "source": [
    "abandon"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "1"
     },
     "metadata": {},
     "execution_count": 7
    }
   ],
   "source": [
    "fruits.index('apple')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "6"
     },
     "metadata": {},
     "execution_count": 12
    }
   ],
   "source": [
    "fruits.index('apple',fruits.index('apple')+1) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "2"
     },
     "metadata": {},
     "execution_count": 13
    }
   ],
   "source": [
    "fruits.count('banana')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "[&#39;apple&#39;,\n &#39;apple&#39;,\n &#39;banana&#39;,\n &#39;banana&#39;,\n &#39;graph&#39;,\n &#39;kiwi&#39;,\n &#39;orange&#39;,\n &#39;pear&#39;,\n &#39;tomato&#39;,\n &#39;tomato&#39;]"
     },
     "metadata": {},
     "execution_count": 17
    }
   ],
   "source": [
    "fruits.sort() #sort()只能用于列表，但是对其他可迭代对象，可以使用sorted()\n",
    "fruits"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "[&#39;tomato&#39;,\n &#39;tomato&#39;,\n &#39;pear&#39;,\n &#39;orange&#39;,\n &#39;kiwi&#39;,\n &#39;graph&#39;,\n &#39;banana&#39;,\n &#39;banana&#39;,\n &#39;apple&#39;,\n &#39;apple&#39;]"
     },
     "metadata": {},
     "execution_count": 18
    }
   ],
   "source": [
    "fruits.reverse()\n",
    "fruits"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "[&#39;tomato&#39;,\n &#39;tomato&#39;,\n &#39;pear&#39;,\n &#39;orange&#39;,\n &#39;kiwi&#39;,\n &#39;graph&#39;,\n &#39;banana&#39;,\n &#39;banana&#39;,\n &#39;apple&#39;,\n &#39;apple&#39;]"
     },
     "metadata": {},
     "execution_count": 19
    }
   ],
   "source": [
    "fruits_a = fruits.copy()\n",
    "fruits_a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "[]"
     },
     "metadata": {},
     "execution_count": 20
    }
   ],
   "source": [
    "fruits_a.clear()\n",
    "fruits_a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}